package com.gitee.wsl.collections.iterator


class ChunkIterator<T>(
    private val it: Iterator<T>,
    private val chunkSize: Int
) : Iterator<List<T>> {
    override fun hasNext(): Boolean {
        return it.hasNext()
    }

    override fun next(): List<T> {
        val ret = ArrayList<T>(chunkSize)
        for (i in 0..<chunkSize) {
            if (it.hasNext()) {
                ret.add(it.next())
            } else {
                break
            }
        }
        return ret
    }
}
